package util;

import java.util.List;

/**
 * User: key
 * ClassName:PageHelper
 * Date: 2023/5/5
 * Time: 20:06
 * description:
 */
public class PageHelper<T> {
    private int pageNum;
    private int pageSize;
    private int totalPage;
    private int totalCount;
    private int startRow;
    List<T> list;

    public int getPageNum() {
        return pageNum;
    }

    public void setPageNum(int pageNum) {
        this.pageNum = pageNum;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public int getTotalPage() {
        return totalPage;
    }

    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }

    public int getTotalCount() {
        return totalCount;
    }

    public void setTotalCount(int totalCount) {
        this.totalCount = totalCount;
    }

    public int getStartRow() {
        return startRow;
    }

    public void setStartRow(int startRow) {
        this.startRow = startRow;
    }

    public List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }

    public PageHelper(int pageNum, int pageSize, int totalCount) {
        this.totalCount = totalCount;
        this.pageSize = pageSize;
        this.totalPage = this.totalCount%this.pageSize!=0?(this.totalCount/this.pageSize)+1:this.totalCount/this.pageSize;
        if(pageNum<1){
            this.pageNum=1;
        }else if(pageNum>this.totalPage){
            this.pageNum=this.totalPage;
        }else {
            this.pageNum = pageNum;
        }
        this.startRow = (this.pageNum-1)*this.pageSize;
    }
}
